﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using QDT.Common;
using QDT.Core.Deals;
using QDT.Core.Projects;

namespace QDT.Web.Admin.Models
{
    public class ProjectRefundModel : RepayModel {

        public ProjectRefundModel(RepayModel model,DebtorRepayment repay) {
            Stage = model.Stage;
            Time = model.Time;
            Interest = model.Interest;
            RemainInterest = model.RemainInterest;
            Principal = model.Principal;
            RemainPrincipal = model.RemainPrincipal;
            Ammount = model.Ammount;
            RemainAmmount = model.RemainAmmount;
            Remark = model.Remark;

            if(repay==null) {
                HasRepay = false;
                Status = RepayStatus.Unknown;
                RepayAmount = 0;
            }else {
                HasRepay = true;
                Status = GetStatus(repay);
                RepayAmount = repay.RepayMoney;
            }
        }

        private RepayStatus GetStatus(DebtorRepayment repay)
        {
            if(repay.TrueRepayTime.GetDayStart()>repay.RepayTime.GetDayStart()) return RepayStatus.Overdue;
            if(repay.TrueRepayTime.GetDayStart()==repay.RepayTime.GetDayStart()) return RepayStatus.Punctual;
            if (repay.TrueRepayTime.GetDayStart() < repay.RepayTime.GetDayStart()) return RepayStatus.Advance; 
            return RepayStatus.Unknown;
        }

        public RepayStatus Status { get; set; }

        public bool HasRepay { get; set; }

        public decimal RepayAmount { get; set; }

    }
}